import java.util.Scanner;
//计算一元二次方程
public class calculateQuadraticEquation {

    private double a,b,c,delta;

    public void input(){
        Scanner In = new Scanner(System.in);
        System.out.println("请填写系数：（aX^2 + bX + c = 0)");
        System.out.println("请输入a:");
        a = In.nextDouble();
        System.out.println("请输入b:");
        b = In.nextDouble();
        System.out.println("请输入c:");
        c = In.nextDouble();
        calculationDelta();
    }

    public void calculationDelta(){
        delta = b * b - 4 * a * c ;
        if (delta < 0){
            System.out.println("无实数解，请重新输入");
            input();
        }else {
            outputRoots();
        }
    }

    public void outputRoots(){
        if (delta == 0){
            double X1 = -b  / (2 * a);
            System.out.println("X1=X2="+X1);
        }else{
            double X1 = (-b + Math.sqrt(delta)) / (2 * a);
            double X2 = (-b - Math.sqrt(delta)) / (2 * a);
            System.out.println("X1="+X1);
            System.out.println("X2="+X2);
        }
    }

    public static void main(String[] args){
        calculateQuadraticEquation solver = new calculateQuadraticEquation();
        solver.input();
    }
}
